Type TileMap
	Const tileSizeW%=32
	Const tileSizeH%=32
	Global _list:TList=New TList
	Field _link:TLink
	
	Field _img:TImage
	Field _array%[tileSizeW,tileSizeH]
	
	Function Create:TileMap()
		Local t:TileMap=New TileMap
		
		t._link=_list.AddLast(t)
		For Local x%=0 To tileSizeW-1
			For Local y%=0 To tileSizeH-1
				t._array[x,y]=0
			Next 
		Next
		
		t._array[2,2]=1
		t._array[2,3]=1
		t._array[2,4]=1
		t._array[3,4]=1
		t._array[3,5]=1
		t._array[2,5]=1
		
		If (TVisual.debug)
			TLine.Create(0,0,32*(tileSizeW-1),0)
			TLine.Create(32*(tileSizeW-1),0,32*(tileSizeW-1),32*(tileSizeH-1))
			TLine.Create(32*(tileSizeW-1),32*(tileSizeH-1),0,32*(tileSizeH-1))
			TLine.Create(0,32*(tileSizeH-1),0,0)
		End If
		
		t._img=LoadAnimImage("Data\Images\tilemap.png",32,32,0,16,MIPMAPPEDIMAGE | FILTEREDIMAGE)
		
		Return t
	End Function
	
	Method _draw()
		For Local x%=0 To tileSizeW-2
			For Local y%=0 To tileSizeH-2
				Local ind%=0
				
				If (_array[x,y]=1)
					ind:+1
				EndIf
				If (_array[x+1,y]=1)
					ind:+2
				EndIf
				If (_array[x+1,y+1]=1)
					ind:+4
				EndIf
				If (_array[x,y+1]=1)
					ind:+8
				EndIf
				
				Local posX#=32*x
				Local posY#=32*y
				TCamera.projectXY(posX,posY)
				Local w#=TCamera.projectW(32)
				Local h#=TCamera.projectH(32)
				
				SetRotation(TCamera.projectR(0))
				SetScale(w/32,h/32)
				
				DrawImage(_img,posX,posY,ind)
				
				SetScale(1,1)
				SetRotation(0)
			Next
		Next
	End Method
End Type